2022-04-26
- Topic: Time
- Clocks: every device has a clock
- Voltage -> electrical oscillation -> 0-1 pulse
- Clock skew (always exists): difference b/w two clocks
- cannot have two clocks fully synchronized
- Clock drift: difference b/w a clock and a nominal perfect reference clock
- There is no way to synchronize two clocks
- Sources of time: International Atomic Time, UTC time, GPS (broadcast UTC)
- Clock synchronization: based on source of time (with error D); sync with each other
- Clock compensation:
- Two clocks drift at rate R msecs/sec
- Max difference 2R msecs/sec
- Mush resync in D/2R to agree within D
- Synchronization methods
- Async:
- Cristian's algorithm:
- Con's: single point of failure/bottleneck, security problem
- Solutions: multiple server, N > 3f rules (f = faulty server)
- Berkeley algorithm:
- characteristic: no central reference clock; consistency matters (not correctness)
- Con's: master election problem
- Network Time Protocol
- Cristian's algorithm:
- Async:
- Logical Time
- Logical time is essentially some kind of causal order
- Recap: state change is an event. This event is "pushed" by some other event (cause)
- Cause implies Order; Order does not necessarily implies Cause
- Event ordering
- Logical clocks (Lamport): monotonically increasing software counter
- one for each process
- message carries timestamp
- If received timestamp later than current, process the message
- If received timestamp earlier than current, there is a PROBLEM
- Solution one: do not process messages that advances time too far
- Solution two: constantly send timestamp even though there is no event
- Solution three: rollback to the state right before the received timestamp and re-do all rollbacked operations, inform others that need to rollback (preemption)
- A memory that keeps every historical operation
- Keep a record for minimum timestamp (reduce memory consumption)